/*
 * 6.1_link.cpp
 *
 *  Created on: 2012-5-18
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

int n, m;
struct Monkey {
	int number;
	Monkey *next;
};

int main (void) {
	while (true) {
		cin >> n >> m;
		if (n == 0) break;
		Monkey *linkHead, *linkTail, *monkey;
		linkHead = linkTail = NULL;
		for (int i=0; i<n; i++) {
			monkey = new Monkey;
			monkey->number = i+1;
			monkey->next = linkHead;
			if (linkTail == NULL)
				linkHead = linkTail = monkey;
			else {
				linkTail->next = monkey;
				linkTail = monkey;
			}
		}
		Monkey *index = linkHead, *preIndex = linkTail;
		for (int i=0; i<n; i++) {
			if (i == n-1) {
				cout << index->number << endl;
				delete index;
				break;
			}
			int nCount = 1;
			while (nCount < m) {
				preIndex = index;
				index = index->next;
				nCount ++;
			}
			if (index == linkHead) linkHead = index->next;
			Monkey *tmp = index;
			preIndex->next = index->next;
			index = index->next;
			delete tmp;
		}
	}
	return 0;
}
